﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using V5_BLL;
using V5_Model;

namespace V5_EShop._Template.Default.Member
{
    public partial class Password : BasicPage
    {
        protected override void OnInit(EventArgs e)
        {
            this.btnSave.Click += new EventHandler(btnSave_Click);
            base.OnInit(e);
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            int id = Input.SetInt(user.ID);
            string UserOldPassword =Input.SetString(this.txtUserOldPassword.Text);
            string UserPassword = Input.SetString(this.txtUserPassword.Text);
            string UserPassword2 = Input.SetString(this.txtUserPassword2.Text);
            if (UserOldPassword == "")
            {
                Pr.RegClientAlert(this, "原密码不能为空!");
                return;
            }
            if (UserPassword == "" || UserPassword.Length == 0)
            {
                Pr.RegClientAlert(this, "新密码不能为空!");
                return;
            }
            if (UserPassword2 == "" || UserPassword2.Length == 0)
            {
                Pr.RegClientAlert(this, "确认密码不能为空!");
                return;
            }
            if (UserPassword != UserPassword2)
            {
                Pr.RegClientAlert(this, "两次输入的密码不相同!");
                return;
            }
            if (id > 0)
            {
                ModelUser model = new BLLUser().GetModel(id);
                model.UserPassword = Input.MD5(UserPassword, 16);
               new BLLUser().Update(model);
                Pr.RegClientAlertAndRedirect(this, "密码修改成功!", HTTPS.ComeUrl);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.check_member_login())
            {
                Response.Redirect("/login.aspx");
            }
        }
    }
}
